﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Customer.aspx.cs" Inherits="Skyworth.CRM.Web.BasicData.Customer" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>销售管理平台 | 客户管理</title>
    <link href="../themes/<%= Request.Cookies["dwz_theme"]!=null? Request.Cookies["dwz_theme"].Value:"default" %>/style.css" rel="stylesheet" type="text/css" />
    <link href="../themes/css/core.css" rel="stylesheet" type="text/css" />
    <link href="../themes/css/pages.css" rel="stylesheet" type="text/css" />
    <link href="../themes/css/wbox.css" rel="stylesheet" type="text/css" />
    <link href="../themes/css/Messagebox.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" href="../themes/css/jquery.cluetip.css" type="text/css" />
    <script src="../javascripts/jquery-1.4.4.min.js" type="text/javascript"></script>
    <script src="../javascripts/dwz.core.js" type="text/javascript"></script>
    <script src="../javascripts/MessageBox.js" type="text/javascript"></script>
    <script src="../javascripts/jquery.tablesorter.min.js" type="text/javascript"></script>
    <script src="../javascripts/wbox.js" type="text/javascript"></script>
    <script src="../javascripts/My97DatePicker/WdatePicker.js" type="text/javascript"></script>
    <script src="../javascripts/jquery.cluetip.min.js" type="text/javascript"></script>
    <script src="../javascripts/dwz.pagination.js" type="text/javascript"></script>
    <script src="../javascripts/json2.js" type="text/javascript"></script>     
    <script type="text/javascript">
        var addWindow;
        //下一页
        function dwzPageBreak(args) {
            $("#pageNum").val(args["pageNum"]);
            $(" #selectedId").val("");
            GetDatas();
        }

        //设置翻页
        function SetPager(pagerId, pageMsgId, numPerPage, currentPage, totalRecords, totalPages) {
            $(pageMsgId).text("  共【" + totalRecords + "】条，【" + totalPages + "】页");
            $(pagerId).each(function () {
                var $this = $(this);
                //alert($this.attr("targetType").toString());
                $this.pagination({
                    targetType: $this.attr("targetType"),
                    totalCount: totalRecords,
                    numPerPage: numPerPage,
                    pageNumShown: $(this).attr("pageNumShown"),
                    currentPage: currentPage
                });
            });
        }

        function DeleteData(id) {
            var paramList = '{"id":"' + id + '"}';
            $.ajax({
                type: "POST",
                url: "Customer.aspx/Delete",
                contentType: "application/json; charset=utf-8",
                data: paramList,
                dataType: "json",
                success: function (data) {
                    if (data.d) {
                        GetDatas();
                    }
                },
                error: function (msg) { $.Messager.Alert({ Title: '系统消息', Message: "发生异常，删除失败！", Icon: IconType.Warning }); }
            })
        }

        function GetDatas() {
            var paramList = new Object();
            paramList.custCode = $("#txtCustNo").val();
            paramList.custLevel = $("#ddlstCustLevel").val();
            paramList.custName = $("#txtCustName").val();
            paramList.orderField = $("#orderField").val();
            paramList.orderValue = $("#orderValue").val();
            paramList.pageIndex = $("#pageNum").val();
            paramList.pagePerSize = $("#numPerPageSelect").val();
            //debugger;
            $.ajax({
                type: "POST",
                url: "Customer.aspx/GetCustomers",
                contentType: "application/json; charset=utf-8",
                data: JSON.stringify(paramList),
                dataType: "json",
                success: function (data) {
                    var dataTable = jQuery.parseJSON(data.d);
                    //填充数据
                    $("#custList tbody").empty();
                    var lists = "";
                    //客户编码,客户名称,客户级别,区号,电话,手机,业务员,客户地址
                    $.each(dataTable.rows, function (i, item) {
                        lists = lists + "<tr rel='" + item.FItemId + "'>" +
                        "<td><a href='javascript:void(0)' rel='CustomerDetail.aspx?CustId=" + item.FItemId + "'>" + item.FNumber + "</a></td>" +
                        "<td><a href='javascript:void(0)' rel='CustomerAddress.aspx?CustId=" + item.FItemId + "'>" + item.FName + "</a></td>" +
                        "<td>" + item.LevelName + "</td>" +
                        "<td>" + item.FQH + "</td>" +
                        "<td>" + item.FTel + "</td>" +
                        "<td>" + item.FMobil + "</td>" +
                        "<td>" + item.EmpName + "</td>" +
                        "<td>" + item.FDree + "</td>" +

                        "<td>" + item.FWebAddress + "</td>" +
                        "<td>" + item.FCustBrand + "</td>" +
                        "<td>" + item.FChannels + "</td>" +
                        "<td>" + item.FCustMarket + "</td>" +
                        "<td>" + item.FProducts + "</td>" +
                        "</tr>";
                    })
                    $(lists).appendTo($("#custList tbody"));

                    //绑定事件
                    $("#custList tr:nth-child(even)").attr('class', "trbg");
                    $("#custList tbody tr").click(function () {
                        $(" #selectedId").val($(this).attr("rel"));
                        $(this).addClass("selected");
                        $(this).siblings("tr").removeClass("selected");
                    }).hover(function () {
                        $(this).addClass('hover');
                    }, function () {
                        $(this).removeClass('hover');
                    })
                    //绑定更新和删除按钮事件
                    $("#btnAdd").click(function () {
                        if ($(this).attr("disabled") != "disabled") {
                            var url = "BasicData/EditCustomer.aspx?Type=add";
                            var pageTitle = "新增客户";
                            parent.navTab.openTab("dlg_page17", url, { title: pageTitle, isIframe: true });
                            return false;
                        }
                    })

                    //addWindow = $("#btnAdd").wBox({ title: "新增客户", requestType: "iframe", target: "EditCustomer.aspx?Type=add", iframeWH: { width: 950, height: 560} });
                    $("#btnUpdate").click(function () {
                        if ($(this).attr("disabled") != "disabled") {
                            var selectId = $("#selectedID").val();
                            if (parseInt(selectId) > 0) {
                                var url = "BasicData/EditCustomer.aspx?Type=update&CustId=" + selectId;
                                var pageTitle = "修改客户";
                                parent.navTab.openTab("dlg_page17", url, { title: pageTitle, isIframe: true });
                                //addWindow = $("#selectedID").wBox({ title: "修改客户信息", requestType: "iframe", target: "EditCustomer.aspx?Type=update&CustId=" + selectId, iframeWH: { width: 950, height: 560} });
                                //addWindow.showBox();
                            }
                            else {
                                $.Messager.Alert({ Title: '系统消息', Message: "请选择要修改的用户！", Icon: IconType.Warning });
                            }
                            return false;
                        }
                    })
                    $("div.button").hover(function () { $(this).addClass("buttonHover"); },
                                                function () { $(this).removeClass("buttonHover"); });
                    $("div.buttonActive").hover(function () { $(this).addClass("buttonActiveHover"); },
                                                function () { $(this).removeClass("buttonActiveHover"); })
                    $("ul.toolBar li").hover(function () { $(this).addClass("hover"); },
                                              function () { $(this).removeClass("hover"); })
                    //绑定表格行事件 
                    $(".tableList table.list").tablesorter();
                    $(".tableList table.list tbody tr:nth-child(even)").attr('class', "trbg");
                    $(".tableList table.list tbody tr").hover(function () { $(this).addClass("hover"); },
                                            function () { $(this).removeClass("hover"); }).click(function () {
                                                $(this).addClass("selected")
                                                $(this).siblings().removeClass("selected");
                                                $("#selectedID").val($(this).attr("rel"));
                                            })//.dblclick(function () {
                                                //addWindow = $("#selectedID").wBox({ title: "修改客户信息", requestType: "iframe", target: "EditCustomer.aspx?Type=update&CustId=" + $(this).attr("rel"), iframeWH: { width: 600, height: 350} });
                                                //addWindow.showBox();
                                            //});
                    $("#custList tbody tr").each(function () {
                        $(this).find("td").eq(0).find("a").cluetip({ cluetipClass: 'jtip', width: '715px', sticky: true, activation: 'click', closePosition: 'title', arrows: true, closeText: '<img src="../themes/images/cancel.png" alt="【关闭】" />' });
                        $(this).find("td").eq(1).find("a").cluetip({ cluetipClass: 'jtip', width: '715px', sticky: true, activation: 'click', closePosition: 'title', arrows: true, closeText: '<img src="../themes/images/cancel.png" alt="【关闭】" />' });
                    });
                    SetPager("#pageId", "#pageMsg", $("#numPerPageSelect").val(), $("#pageNum").val(), dataTable.totalRecords, dataTable.totalPages);
                },
                error: function (msg) { $.Messager.Alert({ Title: '系统消息', Message: "发生异常，获取数据失败！", Icon: IconType.Warning }); },
                beforeSend: function () { $("#LoadingPanel").fadeIn("slow"); },
                complete: function () { $("#LoadingPanel").fadeOut("fast"); }
            })
        }

        $(document).ready(function () {
            //debugger;
            GetDatas();
            $("#btnSearch").click(function () {
                GetDatas();
                return false;
            })
            $("#numPerPageSelect").change(function () {
                $("#pageNum").val(1);
                $("#selectedId").val("");
                GetDatas();
            }) 

            $("#btnDelete").click(function () {
                if ($(this).attr("disabled") != "disabled") {
                    var custId = $("#selectedID").val();
                    if (parseInt(custId) > 0) {
                        $.Messager.Confirm({ Title: '系统警告', Message: '你确定要删除该客户信息吗?', Icon: IconType.Question,
                            Oncallback: function (IsYes, siteMapId) {
                                if (IsYes) { DeleteData(custId); }
                            }
                        })
                    }
                    else {
                        $.Messager.Alert({ Title: '系统消息', Message: "请选择要删除的客户！", Icon: IconType.Warning });
                        return false;
                    }
                    return false;
                }
            })           
        })
    </script>
</head>
<body style="overflow:visible;background-color: #FFF;">
    <div >
        <form id="form1" runat="server"> 
         <div style=" position:absolute;width:100%; height:40px;left:0px; top:0px;">
              <div style="display: block; overflow: auto; margin-bottom: 1px; border-style: solid;
                            border-width: 0px 0 1px 0; background: url('../themes/default/images/pageHeader_bg.png') repeat-x scroll 0 0 #EBF0F5;
                            border-color: #99BBE8; width: 100%; padding: 5px 0px;">
                    <div class="searchBar" style="padding:4px 5px;">
                    <ul >
                        <li style="float: left;">
                            <span >客户级别：</span>
                            <asp:DropDownList ID="ddlstCustLevel" runat="server">
                                <asp:ListItem Selected="True" Value="0">请选择</asp:ListItem>
                                <asp:ListItem Value="1">A</asp:ListItem>
                                <asp:ListItem Value="2">B</asp:ListItem>
                                <asp:ListItem Value="3">C</asp:ListItem>
                                <asp:ListItem Value="4">D</asp:ListItem>
                            </asp:DropDownList>
                        </li>
                        <li style="float: left;">
                            <span >客户编号：</span>
                            <asp:TextBox ID="txtCustNo" runat="server"></asp:TextBox>
                        </li>
                        <li style="float: left;">
                            <span >客户名称：</span>
                            <asp:TextBox ID="txtCustName" runat="server"></asp:TextBox>
                        </li>
                        <li style="float: left; padding-left:20px">
                            <div class="buttonActive">
                                <div class="buttonContent">
                                    <asp:Button ID="btnSearch" runat="server" Text="查询" ToolTip="查询客户信息" 
                                        CssClass="serverButton" />
                                </div>
                            </div>
                        </li>
                        <li style="clear: both" ></li>
                    </ul>
                </div>

               </div>
          </div>
         <div style=" position:absolute;width:100%;left:0px;top:40px; height:30px;">                         
             <div class="panelBar" style="width: 100%;">
                            <ul class="toolBar">
                                <li class=""><asp:LinkButton ID="btnAdd" CommandArgument="2" runat="server" CssClass="add"><span>添加客户</span></asp:LinkButton></li>
                                <%--<li class=""><a href="EditCustomer.aspx" class="add" target="navTab" isIframe="false" rel="dlg_page13"><span>添加</span></a>
                                </li>--%>
                                <li class="line">line</li>
                                <li class=""><asp:LinkButton ID="btnUpdate" CommandArgument="3" runat="server" CssClass="edit"><span>修改客户</span> </asp:LinkButton></li>
                                <li class="line">line</li>
                                <li class=""><asp:LinkButton ID="btnDelete" CommandArgument="4" runat="server" CssClass="delete"><span>删除客户</span> </asp:LinkButton></li>
                                <li class="line">line</li>
                                <%--<li><a class="icon" href="javascript:;"><span>导入EXCEL</span></a></li>--%>
                                <li>
                                <%--<asp:Button ID="btnhidDelete" runat="server" Text="" style="display:none;" onclick="btnhidDelete_Click" />--%>
                                <input type="hidden" style="display:none;" id="selectedID" runat="server" />
                                </li>
                            </ul>
                        </div>         
         </div>   
         <div style=" position:absolute; left:0px; top:72px;width:100%">
              <div class="pageContent">
            <div class="tableList">
                <table class="list" id="custList" width="100%">
                    <thead>
                        <tr>   
                            <th  style="cursor: pointer;" >
                                <span style="float:left">客户编码</span>
                               <span style="float:right;" class="sortIcon"></span>                                
                            </th>                         
                            <th  style="cursor: pointer;" class="headerSortUp">
                               <span style="float:left">客户名称</span>
                               <span style="float:right;" class="sortIcon"></span>
                            </th>     
                            <th  style="cursor: pointer;">
                               <span style="float:left">客户级别</span>
                               <span style="float:right;" class="sortIcon"></span>
                            </th>                             
                            <th style="cursor: pointer;">
                               <span style="float:left">区号</span>
                            </th>     
                            <th  style="cursor: pointer;">
                               <span style="float:left">电话</span>
                            </th>     
                             <th  style="cursor: pointer;">
                               <span style="float:left">手机</span>
                            </th>   
                            
                            <th  style="cursor: pointer;">
                               <span style="float:left">业务员</span>
                            </th>     
                            <%--<th width="300" style="cursor: pointer;">
                               <span style="float:left">区域内码</span>
                            </th>     --%>
                            <th  style="cursor: pointer;">
                               <span style="float:left">客户地址</span>
                            </th>  
                            <th  style="cursor: pointer;">
                               <span style="float:left">客户网站</span>
                            </th> 
                            <th  style="cursor: pointer;">
                               <span style="float:left">客户品牌</span>
                            </th>  
                            <th  style="cursor: pointer;">
                               <span style="float:left">销售渠道</span>
                            </th>  
                            <th  style="cursor: pointer;">
                               <span style="float:left">目标市场</span>
                            </th>  
                            <th  style="cursor: pointer;">
                               <span style="float:left">主要经营产品</span>
                            </th>                                
                        </tr>
                    </thead>
                    <tbody>                     
                    </tbody>                    
                </table>
                </div>
                <div class="panelBar">
                                            <div class="pages">
                                                <span>每页显示</span>
                                                <div style="float: left">
                                                    <select id="numPerPageSelect" runat="server">                                                       
                                                        <option>10</option>
                                                        <option selected="selected">20</option>                                                       
                                                        <option>30</option>                                                        
                                                        <option>50</option>
                                                    </select>
                                                </div>
                                                <span id="pageMsg"></span>
                                            </div>
                                            <div id="pageId" class="pagination" targettype="navTab" pagenumshown="10">
                                            </div>
                                        </div>   
            </div>
            <div>
                <input type="hidden" id="pageNum" name="pageNum" value="1" runat="server" />
                <input type="hidden" id="orderField" name="orderField" value="FNumber" runat="server" />
                <input type="hidden" id="orderValue" name="orderValue" value="asc" runat="server" />
            </div>
         </div> 
         <div class="panelFooter">
                    <div class="panelFooterContent">
                    </div>
         </div>
         <div id="LoadingPanel" style="display: none;">
            <div id='background' class='background'>
            </div>
            <div id='progressBar' class='progressBar'>
                数据加载中，请稍等...</div>
         </div>
         </form>
    </div>
</body>
</html>
